#include "codeedit.h"
#include "highlighter.h"
#include <QFont>
#include <QDebug>
#include <QKeyEvent>

CodeEdit::CodeEdit(QWidget *parent) :
    QTextEdit(parent)
{
    QFont font;
    font.setFamily("Courier");
    font.setFixedPitch(true);
    font.setPointSize(10);
    font.setStyleStrategy(QFont::PreferAntialias);
    setFont(font);
    setTabStopWidth(30);

    highlighter = new Highlighter(document());
}


bool CodeEdit::findFunctionDeclaration(const QString &func)
{
    QString fn = func;
    fn.remove(QRegExp("\\(.*\\)"));
    QString exp = "\\bfunction\\s*"+fn+"\\(.*\\)";
    QTextCursor tc = document()->find(QRegExp(exp));

    if(!tc.isNull())
    {
        setTextCursor(tc);
        return true;
    }
    else
    {
        return false;
    }
}

void CodeEdit::keyPressEvent(QKeyEvent *e)
{
    //qDebug()<<e->key();
    QTextEdit::keyPressEvent(e);
}
